﻿/**********************************************************
*-----------------------------------*
* flareJ JavaScript Library
*-----------------------------------*
* 作者:Joe_Sky
* 邮箱:hitomi_doax@tom.com
* 最后更新时间:2011-6-26
*-----*-----*-----*-----*-----*-----*
* 基于jQuery
***********************************************************/

/*----------------------------------------------*
* flareJ.Panel
*-------*-------*-------*-------*-------*-------*
* 面板
*-------*-------*-------*-------*-------*-------*
* (必须)需引入flareJ.Base.js
* (必须)需引入flareJ.LoadMask.js
*----------------------------------------------*/
(function ($) {
    var FJ = $.flareJ, flareJ = FJ;

    /************************************************************
    *-----------------------------------------------------------*
    *                           面板
    *-----------------------------------------------------------*
    *************************************************************
    *-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*
    * 
    *-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*
    * 
    ************************************************************/
    this.PanelJ = this.PJ = FJ.PanelJ = FJ.PJ = FJ.CJ.extend({
        //#region 构造方法
        init: function (elemObj, settings) {
            //参数
            this._super(elemObj, $.extend(true, {
                fjType: "PJ",
                renderTo: elemObj,                          //要加载到的容器
                renderType: "append",
                layout: "normal",
                layoutCfg: {
                    acHeight: 25
                },
                title: "面板",                                                                        //标题
                imgTitleSrc: PJ.imgFolderSrc + (FJ.isIE6 ? "HeadIcon1.gif" : "HeadIcon1.png"),                  //标题图片路径
                imgCloseSrc: PJ.imgFolderSrc + (FJ.isIE6 ? "FDnewButton.gif" : "FDnewButton.png"),    //关闭按钮图片路径
                imgSize: { w:16,h:16 },                                                        //标题图片大小
                imgLoadSrc: PJ.imgFolderSrc + "loading2.gif",                                          //Loading条图片路径
                isCanMinimize: true,                                                                    //是否可最小化
                divState: "max",                                                                        //层状态(最大或最小化)
                minSpeed: 500,
                loadSpeed: 1,                                                                         //加载内容页的速度
                borderWidth: 1,                                                                         //边框宽度
                borderWidthB: 0,
                hasIfr: false,                             //是否加载IE6下遮挡的iframe
                speed: 500,                                //弹出,收回速度
                leftF: null,                               //弹出后左边距
                topF: null,                                //弹出后上边距
                widthB: "100%",                            //内容层最大宽度
                heightB: "100%",                           //内容层最大高度
                bodyPadding: { t: 0, r: 0, b: 0, l: 0 },   //内容层补间宽度
                outPadding: { t: 0, r: 0, b: 0, l: 0 },    //外层补间宽度
                zIndex: 10,                                //层在页面中的Z轴位置
                loadType: "html",                          //加载内容层类型(html、ajax、iframe)
                fnHtml: null,                              //加载html到内容层方法
                pHtml: null,                               //加载html到内容层方法参数
                loadDomType: "append",                     //加载html形式
                bodyUrl: null,                             //加载内容层路径(用ajax、iframe方式加载)
                isAsync: true,                             //用ajax加载内容层时是否同步
                items: [],                                 //内容层对象集合
                showLoading: false,                        //加载内容页时是否显示loading层
                headHeight: 25,                            //头部高度
                footHeight: 27,                            //底部高度
                cbS: null,                                 //展示回调方法
                cbS2: null,                                //展示回调方法(每次加载内容层操作都执行)
                cbR: null,                                 //重刷回调方法
                cbC: null,                                 //关闭回调方法
                cbM: null,                                 //提示框回调方法
                showHead: true,                           //是否显示头部
                showFoot: true,                           //是否显示底部
                radius: 0,                                //圆角弧度
                maxMinStyle: "maxmin",                    //最大最小化按钮样式
                useImgBorder: null,                       //是否使用图片背景
                btns: [                                   //按钮
                    {
                    txt: "按钮1",
                    fn: null
                }
                ],
                colorParams: {                             //颜色参数
                    //borderOut: "#A2CEF1",
                    bgColor: "#50B7E4",                    //背景色
                    bgColorBody: "#ffffff",                //内容层背景(上)#e6f5fa
                    bgColorBodyB: "#ffffff",               //内容层背景(下)
                    borderBody: "#0f7cad",                 //内容层边框
                    fontColorBody: "#036ec1",                 //内容层字体颜色
                    scrollbarFaceColor: "#7ce0f9",         //滚动条颜色1
                    scrollbarHighlightColor: "#fff",       //滚动条颜色2
                    scrollbarShadowColor: "#2cc9f0",       //滚动条颜色3
                    scrollbar3dlightColor: "#2cc9f0",      //滚动条颜色4
                    scrollbarArrowColor: "#158aa7",        //滚动条颜色5
                    scrollbarTrackColor: "#c3edf7",        //滚动条颜色6
                    scrollbarDarkshadowColor: "#fff",       //滚动条颜色7
                    bgColorHead: "#50B7E4",                                                             //头部背景色
                    bgColorHeadJ: "#3CA4D7",                                                            //头部背景渐变色(下)
                    bgColorHeadJT: "#6DD5FA",                                                           //头部背景渐变色(上)
                    bgColorHeadU: "#62c1eb",                                                            //头部上半边背景色(非IE浏览器下显示)
                    bgColorFoot: "#50B7E4",                                                             //底部背景色
                    bgColorFootJ: "#6DD5FA",                                                            //底部背景渐变色(下)
                    bgColorFootJT: "#3CA4D7",                                                           //底部背景渐变色(上)
                    bgColorFootU: "#62c1eb",                                                            //底部上半边背景色(非IE浏览器下显示)
                    fontColorHead: "#ffffff",                                                           //头部字体颜色
                    buttonColor: "transparent",                                                         //按钮颜色
                    buttonColorG: "#ffffff"                                                             //鼠标悬停按钮颜色
                },
                eType: (function(j){
                    return {
                        //afterrender: j
                    }
                })("PJ")
            }, settings));

            //建立参数别名
            if (this.p.loadHTML != null) this.p.fnHtml = this.p.loadHTML;
            if (this.p.loadHTMLParams != null) this.p.pHtml = this.p.loadHTMLParams;
            if (this.p.urlType != null) this.p.loadType = this.p.urlType;
            if (this.p.callbackS != null) this.p.cbS2 = this.p.callbackS;
            if (this.p.callbackC != null) this.p.cbC = this.p.callbackC;

            this.pjBody = null;     //内容层
            this.pjLoad = null;     //loading半透明层
            this.objId = null;    //选中元素ID
            this.objOff = null;   //选中元素边距对象
            this.pjHead = null;   //头部
            this.pjTitle = null;  //标题
            this.pjHeadTop = null;  //标题上部
            this.pjBtnClose = null;  //关闭按钮
            this.pjBtnMin = null;    //最小化按钮
            this.actualWidth = this.p.widthF;    //实际宽度
            this.actualHeight = this.p.heightF;  //实际高度
            this.p.layoutCfg = $.extend(this.p.layoutCfg, {  //布局参数
                layout: this.p.layout,
                items: this.p.items
            });

            //执行初始化
            this.initFn();
        },
        //#endregion

        //#region 初始化
        initFn: function () {
            this._super();

            if(this.p.useImgBorder)
                this.p.colorParams.fontColorHead = "#000";

            this.create();
        },
        //#endregion

        //#region 构建
        create: function () {
            var thiz = this;
            this._super();
            var isFilter = FJ.isIEno9 || (FJ.isIE9 && this.p.radius <= 0);// || FJ.isWebkit || FJ.isFF;

            //#region 外层
            //修改外层属性
            this.divOut.attr("id", "PJ_" + this.objId).addClass("pj").css({
                paddingTop: (this.p.borderWidth > 1 ? this.p.headHeight + 2 : this.p.headHeight + 1) + "px",
                paddingBottom: (this.p.borderWidth > 1 ? this.p.footHeight + 2 : this.p.footHeight + 1) + "px",
                paddingLeft: this.p.outPadding.l,
                paddingRight: this.p.outPadding.r,
                zIndex: this.p.zIndex,
                width: this.p.widthF,
                height: this.p.heightF,
                left: this.p.leftF,
                top: this.p.topF,
                backgroundColor: FJ.isIEno9 ? this.p.colorParams.bgColorHeadJ : this.p.colorParams.bgColor
            });
            //#endregion

            //#region 头部
            //面板头部
            this.pjHead = $('<div id="pj_head_' + this.objId + '" class="pj_head"></div>');
            this.pjHead.css("background-color", this.p.colorParams.bgColorHead).css("height", this.p.headHeight + "px");
            if (isFilter) {  //头部设置为渐变色
                if(FJ.isIE){
                    this.pjHead[0].style.filter = "alpha(opacity=100) progid:DXImageTransform.Microsoft.Gradient(GradientType=0, EndColorStr='" + this.p.colorParams.bgColorHeadJ + "', StartColorStr='" + this.p.colorParams.bgColorHeadJT + "')";
                }
//                else {
//                    this.pjHead.css({
//                        background: (function(){
//                            if(FJ.isWebkit){
//                                return "-webkit-gradient(linear, left top, left bottom , from("+thiz.p.colorParams.bgColorHeadJT+"), to("+thiz.p.colorParams.bgColorHeadJ+"))"
//                            }
//                            else if(FJ.isFF){
//                                return "-moz-linear-gradient(top, "+thiz.p.colorParams.bgColorHeadJT+", "+thiz.p.colorParams.bgColorHeadJ+")";
//                            }
//                        })()
//                    });
//                }
            }
            else {
                this.pjHeadTop = $('<div class="pj_headTop" style="background:' + this.p.colorParams.bgColorHeadU + ';height:' + this.p.headHeight / 2.0 + 'px"></div>');
            }
            this.pjHead.css({ borderBottom: (this.p.borderWidth >= 3 ? this.p.borderWidth - 1 : this.p.borderWidth) + "px solid " + (isFilter ? this.p.colorParams.bgColorHeadJ : this.p.colorParams.bgColor) });

            //是否显示头部
            if (!this.p.showHead) {
                this.divOut.css({ paddingTop: 0 });
                this.pjHead.hide();
            }

            this.pjHeadImg = $('<img style="width:'+this.p.imgSize.w+'px;height:'+this.p.imgSize.h+'px;" class="pj_img" src="' + this.p.imgTitleSrc + '" />');
            this.pjTitle = $('<div id="pj_title_' + this.objId + '" class="pj_title" style="color:' + this.p.colorParams.fontColorHead + ';">' + this.p.title + '</div>');

            //关闭按钮
            this.pjBtnClose = $('<div title="关闭" class="pj_close" style="background-color:' + this.p.colorParams.buttonColor + ';"></div>').click(function () {
                thiz.close();
            });

            //最小化按钮
            var maxminS;
            if (this.p.maxMinStyle == "maxmin") {
                maxminS = "pj_minImg";
            }
            else if (this.p.maxMinStyle == "expcol") {
                maxminS = "pj_colImg";
            }
            this.pjBtnMin = $('<div title="最小化" class="pj_min ' + maxminS + '" style="background-color:' + this.p.colorParams.buttonColor + ';"></div>').click(function (evt) {
                thiz.maxMin();
                evt.stopPropagation();
            });

            //鼠标经过按钮时变色
            if (!this.p.useImgBorder) {
                this.pjBtnClose.hover(function () {
                    $(this).css("border", "1px solid " + thiz.p.colorParams.buttonColorG).css("margin", "-1px 1px 0 0");
                    thiz.pjBtnMin.css("margin-right", "1px");
                }, function () {
                    $(this).css("border", "0").css("margin", "0 2px 0 0");
                    thiz.pjBtnMin.css("margin-right", "2px");
                });
                this.pjBtnMin.hover(function () {
                    $(this).css("border", "1px solid " + thiz.p.colorParams.buttonColorG).css("margin", "-1px 1px 0 0");
                }, function () {
                    $(this).css("border", "0").css("margin", "0 2px 0 0");
                });
            }

            //在IE6下需要做的操作
            if (FJ.isIE6) {
                if (this.p.hasIfr) {
                    //创建一个和层一样大的Iframe解决div无法遮盖select问题
                    this.pjIframe = $("<iframe id='pj_ifr_" + this.objId + "' frameborder='0' scrolling='no' style='display:none;width:0;height:0;filter:alpha(opacity=0);-moz-opacity:0;position:absolute;top:0;left:0;z-index:" + (this.p.zIndex - 1) + ";'></iframe>");
                    this.pjIframe.prependTo(this.p.renderTo);
                }

                //关闭按钮位置调整
                this.pjBtnClose.css("margin-right", "1px");
            }

            //绘制头部
            if (isFilter) {
                this.pjHead.addClass("pj-drj").append(this.pjHeadImg.addClass("pj-drj")).append(this.pjTitle.addClass("pj-drj")).append(this.pjBtnClose).append(this.pjBtnMin);
            }
            else {
                this.pjHead.addClass("pj-drj").append(this.pjHeadTop.addClass("pj-drj")).append(this.pjHeadImg.addClass("pj-drj")).append(this.pjTitle.addClass("pj-drj")).append(this.pjBtnClose).append(this.pjBtnMin);
            }
            this.pjHead.css("cursor", "auto");

            //设置是否可最小化
            if (!this.p.isCanMinimize) {
                this.pjBtnMin.hide();
            }
            //#endregion

            //#region 内容层
            //内容层
            this.pjBody = $('<div id="pj_body_' + this.objId + '" class="pj_body" style="scrollbar-face-color:'
                    + this.p.colorParams.scrollbarFaceColor + ';scrollbar-highlight-color:'
                    + this.p.colorParams.scrollbarHighlightColor + ';scrollbar-shadow-color:'
                    + this.p.colorParams.scrollbarShadowColor + ';scrollbar-3dlight-color:'
                    + this.p.colorParams.scrollbar3dlightColor + ';scrollbar-arrow-color:'
                    + this.p.colorParams.scrollbarArrowColor + ';scrollbar-track-color:'
                    + this.p.colorParams.scrollbarTrackColor + ';scrollbar-darkshadow-color:'
                    + this.p.colorParams.scrollbarDarkshadowColor + ';"></div>');
            this.pjBody.css({
                color: this.p.colorParams.fontColorBody,
                backgroundColor: this.p.colorParams.bgColorBody,
                width: this.p.widthB,
                height: this.p.heightB,
                border: this.p.borderWidthB + "px solid " + this.p.colorParams.borderBody,
                padding: this.p.bodyPadding.t + "px " + this.p.bodyPadding.r + "px " + this.p.bodyPadding.b + "px " + this.p.bodyPadding.l + "px"
            });

            //实际存放内容html的层
            this.bodyIn = $('<div class="pj_bodyIn"></div>');

            //loading半透明层
            this.pjLoad = $(this.pjBody).LMJ({
                imgSrc: this.p.imgLoadSrc
            });

            //内容层背景IE中为渐变色
            if (FJ.isIE) {
                if (this.p.colorParams.bgColorBody != "transparent") {
                    this.bodyIn[0].style.filter = "alpha(opacity=100) progid:DXImageTransform.Microsoft.Gradient(GradientType=0, EndColorStr='" + this.p.colorParams.bgColorBodyB + "', StartColorStr='" + this.p.colorParams.bgColorBody + "')";
                }
            }
            //#endregion

            //#region 底部
            //面板底部
            this.pjFoot = $('<div id="pj_foot_' + this.objId + '" class="pj_foot"></div>');
            this.pjFoot.css("background-color", this.p.colorParams.bgColorFoot).css("height", this.p.footHeight + "px");
            if (isFilter) {
                this.pjFoot[0].style.filter = "alpha(opacity=100) progid:DXImageTransform.Microsoft.Gradient(GradientType=0, EndColorStr='" + this.p.colorParams.bgColorFootJ + "', StartColorStr='" + this.p.colorParams.bgColorFootJT + "')";
            }
            this.pjFoot.css({ borderTop: (this.p.borderWidth >= 3 ? this.p.borderWidth - 1 : this.p.borderWidth) + "px solid " + (isFilter ? this.p.colorParams.bgColorFootJT : this.p.colorParams.bgColor) });

            //是否显示底部
            if (!this.p.showFoot) {
                this.divOut.css({ paddingBottom: 0 });
                this.pjFoot.hide();
            }

            //按钮
            if (this.p.btns != null) {
                for (var i = 0; i < this.p.btns.length; i++) {
                    this["pjBtn" + (i + 1)] = $("<input type='button' value='" + this.p.btns[i].txt + "' class='pj_btn' />").addClass("pj_btnBottom");
                    (function (i) {
                        thiz["pjBtn" + (i + 1)].click(function () {
                            if (thiz.p.btns[i].fn != null) {
                                thiz.p.btns[i].fn.call(thiz);
                            }
                        });
                    })(i);
                    this.pjFoot.append(this["pjBtn" + (i + 1)]);
                }
            }
            else {
                if (FJ.isIE6) this.pjFoot.css("font-size", 0);
            }
            //#endregion

            //#region 设置圆角
            var radius;
            if (!this.p.useImgBorder) {
                if (FJ.isFF) {
                    if (!FJ.isFF4up)
                        radius = "-moz-border-radius";
                    else
                        radius = "border-radius";
                }
                else if (FJ.isWebkit) {
                    radius = "-webkit-border-radius";
                }
                else if (FJ.isOpera || FJ.isIE9) {
                    radius = "border-radius";
                }
                if (radius && this.p.radius > 0) {
                    this.divOut.css(radius, this.p.radius + "px");
                    this.pjHead.css(radius, this.p.radius + "px " + this.p.radius + "px 0 0");
                    if (this.pjHeadTop) this.pjHeadTop.css(radius, this.p.radius + "px " + this.p.radius + "px 0 0");
                    this.pjFoot.css(radius, "0 0 " + this.p.radius + "px " + this.p.radius + "px");
                }
            }
            this.radiusStyle = radius;
            //#endregion

            //#region 使用图片背景
            if (this.p.useImgBorder) {
                this.divOut.css({ border: 0, backgroundColor: "transparent", paddingTop: parseFloat(this.divOut.css("padding-top")) + 4 });
                this.pjHead.css({ border: 0, backgroundColor: "transparent" });
                if (this.pjHeadTop) this.pjHeadTop.css({ backgroundColor: "transparent" });
                this.pjFoot.css({ border: 0, backgroundColor: "transparent" });
                this.pjHead[0].style.filter = "";
                this.pjFoot[0].style.filter = "";
                this.pjBody.css({ border: 0 });
                this.p.borderWidthB = 0;
                this.pjTitle.css({ fontWeight: "normal" });
                //this.pjTitle[0].style.filter = "alpha(opacity=100)";

                //修改按钮样式
                this.pjBtnClose.css({
                    width: 29,
                    height: 20,
                    backgroundImage: "url("+PJ.imgFolderSrc+"closeBtn.jpg)",
                    margin: (FJ.isIEno9 ? "1" : "-1") + "px "+(FJ.isIE6 ? "5" : "10" )+"px 0 0"
                });

                this.pjBg = $('<div class="pj_bg"><table class="pj_bg_table"><tr><td class="pj_bg1"></td><td style="margin:auto;padding:auto;" class="pj_bg2"></td><td class="pj_bg3"></td></tr><tr><td class="pj_bg4"></td><td class="pj_bg5"></td><td class="pj_bg6"></td></tr><tr><td class="pj_bg7"></td><td class="pj_bg8"></td><td class="pj_bg9"></td></tr></table></div>');
                if (FJ.isIEno9)
                    this.pjBg.find(".pj_bg4").css({ height: this.p.heightF + 20 });

                if (this.p.useImgBorder)
                    this.divOut.append(this.pjBg);
            }
            //#endregion

            this.divOut.append(this.pjHead).append(this.pjBody.append(this.bodyIn)).append(this.pjFoot);

            this.fire("afterrender", "PJ");
            return this;
        },
        //#endregion

        //#region 显示
        show: function () {
            this._super();
            this.loadBody("show");
            this.fixSize();
            return this;
        },
        //#endregion

        //#region 关闭
        close: function () {
            this._super();
            if (this.p.cbC != null) {
                this.p.cbC();
            }
        },
        //#endregion

        //#region 加载内容层
        loadBody: function (type) {
            var thiz = this;
            thiz.showLoad(true);             //显示loading

            var fn = function () {
                switch (thiz.p.loadType) {
                    case "html":
                        if (thiz.p.items != null && thiz.p.items.length > 0) {   //解析json形式加载内容层
                            if (thiz.p.loadDomType == "html") {
                                thiz.bodyIn.empty();
                            }

                            //加载布局
                            thiz.laj = $(thiz.bodyIn).LAJ(thiz.p.layoutCfg);
                        }
                        else {   //直接加载
                            if (thiz.p.fnHtml != null) {
                                var html = thiz.p.fnHtml.call(thiz, thiz.p.pHtml);
                                if (thiz.p.loadDomType == "html") {
                                    thiz.bodyIn.html(html);
                                }
                                else if (thiz.p.loadDomType == "append") {
                                    thiz.bodyIn.append(html);
                                }
                            }
                        }
                        thiz.loadBodyCB(type);  //执行回调函数
                        break;

                    case "ajax":
                        $.ajax({
                            type: "get",
                            url: thiz.p.bodyUrl,
                            cache: false,
                            async: thiz.p.isAsync,  //是否同步
                            success: function (resp) {
                                thiz.bodyIn.html(resp);
                                thiz.loadBodyCB(type);  //执行回调函数
                            }
                        });
                        break;

                    case "iframe":
                        var urlI = thiz.p.bodyUrl.indexOf("?") != -1 ? (thiz.p.bodyUrl + "&ts=" + new Date().getTime()) : (thiz.p.bodyUrl + "?ts=" + new Date().getTime());
                        thiz.bodyIn.html("<iframe id='iframe_" + thiz.objId + "' style='position:absolute;z-index:0;border:0;' src='" + urlI + "' frameborder=none width=100% height=100%></iframe><div id='moveIframe_" + thiz.objId + "' style='display:none;width:100%;height:100%;position:absolute;z-index:100003;'></div>");
                        thiz.loadBodyCB(type);  //执行回调函数
                        break;
                }
            };

            if (thiz.p.loadSpeed > 1) {
                setTimeout(function () {   //加载内容层
                    fn();
                }, thiz.p.loadSpeed);
            }
            else {
                fn();
            }
        },
        //#endregion

        //#region 加载内容层完毕
        loadBodyCB: function (type) {
            this.fixBody();
            switch (type) {
                case "show":
                    if (this.p.cbS != null) {
                        this.p.cbS.call(this);
                    }
                    break;
                case "reload":
                    this.p.loadDomType = this.p._loadDomType;
                    if (this.p.cbR != null) {
                        this.p.cbR.call(this);
                    }
                    break;
            }
            if (this.p.cbS2 != null) {
                this.p.cbS2.call(this);
            }
            this.showLoad(false);
        },
        //#endregion

        //#region 重刷内容层
        reload: function (url) {
            if (url != null) { this.p.bodyUrl = url; }  //修改内容层url
            this.p._loadDomType = this.p.loadDomType;
            this.p.loadDomType = "html";
            this.loadBody("reload");
        },
        //#endregion

        //#region 显示/关闭loading
        showLoad: function (isShow) {
            if (this.p.showLoading && this.pjLoad != null) {
                if (isShow) {
                    this.pjLoad.show();
                }
                else {
                    this.pjLoad.hide();
                }
            }
        },
        //#endregion

        //#region 修改标题
        alterTitle: function (str) {
            if (this.pjTitle != null) {
                this.pjTitle.html(str);
            }
        },
        //#endregion

        //#region 修改层大小
        alterSize: function (settings) {
            //修改层参数
            this.alterP(settings);
            this.divOut.css({ width: this.p.widthF, height: this.p.heightF });
            this.pjBody.css({ width: this.p.widthB, height: this.p.heightB });
        },
        //#endregion

        //#region 改变为最小化
        changeMin: function () {
            if (this.pjBtnMin != null) {
                if (this.p.divState == "max") {
                    if (thiz.rej != null) {
                        thiz.rej.p.onlyH = true;
                    }
                    this.divOut.css({ height: "0", borderBottom: "2px solid #48b7d9" });
                    if (FJ.isIE6) {
                        this.pjIframe.css({ height: "30" });
                    }
                    this.pjBtnMin.removeClass("pj_minImg").addClass("pj_maxImg").attr("title", "最大化");
                    this.p.divState = "min";
                }
            }
        },
        //#endregion

        //#region 模拟点击关闭按钮
        clickClose: function () {
            if (this.pjBtnClose != null) {
                this.pjBtnClose.click();
            }
        },
        //#endregion

        //#region 模拟点击最小化按钮
        clickMin: function () {
            if (this.pjBtnMin != null) {
                this.pjBtnMin.click();
            }
        },
        //#endregion

        //#region 最小化
        min: function (speed) {
            if (this.pjBtnMin != null) {
                if (this.p.divState == "max") {
                    this.maxMin(null, speed);
                }
            }
        },
        //#endregion

        //#region 最大化
        max: function (speed) {
            if (this.pjBtnMin != null) {
                if (this.p.divState == "min") {
                    this.maxMin(null, speed);
                }
            }
        },
        //#endregion

        //#region 最大最小化
        maxMin: function (cb, speed) {
            var thiz = this;
            if (speed == null) speed = this.p.minSpeed;
            if (this.pjBtnMin != null) {
                if (this.p.divState == "max") {
                    this.p.divState = "onMin";
                    if (this.rej != null) {
                        this.rej.p.onlyH = true;
                    }
                    this.divOut.animate({ height: "0px" }, speed, function () {
                        if (!thiz.p.useImgBorder)
                            thiz.divOut.css({ borderBottom: (thiz.p.borderWidth >= 3 ? thiz.p.borderWidth - 2 : 1) + "px solid " + thiz.p.colorParams.borderOut });
                        if (FJ.isIE6 && thiz.p.hasIfr) {
                            thiz.pjIframe.css({ height: (thiz.p.borderWidth >= 3 ? thiz.p.borderWidth + 25 : 26) });
                        }
                        if (thiz.p.maxMinStyle == "maxmin") {
                            thiz.pjBtnMin.removeClass("pj_minImg").addClass("pj_maxImg").attr("title", "最大化");
                        }
                        else if (thiz.p.maxMinStyle == "expcol") {
                            thiz.pjBtnMin.removeClass("pj_colImg").addClass("pj_expImg").attr("title", "展开");
                        }
                        if (thiz.p.showFoot) {
                            thiz.divOut.css({ paddingBottom: 0 });
                            thiz.pjFoot.hide();
                        }
                        if (FJ.isIE7)
                            thiz.fixSize();
                        thiz.pjBody.hide();
                        thiz.p.divState = "min";
                        if (cb) cb();
                    });
                }
                else if (this.p.divState == "min") {
                    if (this.rej != null) {
                        this.rej.p.onlyH = false;
                    }
                    this.pjBody.show();
                    this.divOut.animate({ height: this.actualHeight }, speed, function () {
                        if (FJ.isIE6)
                            thiz.fixSize();
                        if (!thiz.p.useImgBorder)
                            thiz.divOut.css({ borderBottom: thiz.p.borderWidth + "px solid " + thiz.p.colorParams.borderOut });
                        if (FJ.isIE6 && thiz.p.hasIfr) {
                            thiz.pjIframe.css({ height: thiz.actualHeight + (thiz.p.borderWidth >= 3 ? thiz.p.borderWidth + 27 : 28) });
                        }
                        if (thiz.p.maxMinStyle == "maxmin") {
                            thiz.pjBtnMin.removeClass("pj_maxImg").addClass("pj_minImg").attr("title", "最小化");
                        }
                        else if (thiz.p.maxMinStyle == "expcol") {
                            thiz.pjBtnMin.removeClass("pj_expImg").addClass("pj_colImg").attr("title", "收缩");
                        }
                        if (thiz.p.showFoot) {
                            thiz.divOut.css({ paddingBottom: (thiz.p.borderWidth > 1 ? thiz.p.footHeight + 2 : thiz.p.footHeight + 1) + "px" });
                            thiz.pjFoot.show();
                        }
                        if (FJ.isIE7)
                            thiz.fixSize();
                        thiz.p.divState = "max";
                        if (cb) cb();
                    });
                }
            }
        },
        //#endregion

        //#region 解决ie下第一次加载内容层不显示
        fixBody: function () {
            if (FJ.isIE) {
                this.pjBody.css("height", this.pjBody[0].clientHeight).css("height", this.p.heightB);
            }
        },
        //#endregion

        //#region 修正面板大小
        fixSize: function () {
            if (FJ.isIE6) {
                this.pjHead.css({ width: "100%" }).css({ width: this.pjHead[0].clientWidth + this.p.outPadding.l + this.p.outPadding.r });
                this.pjFoot.css({ width: "100%" }).css({ width: this.pjFoot[0].clientWidth + this.p.outPadding.l + this.p.outPadding.r });
                if(this.p.useImgBorder)
                    this.pjBg.css({ width: "100%" }).css({ width: this.pjBg[0].clientWidth + this.p.outPadding.l + this.p.outPadding.r });
                this.pjIframe.css({ width: this.divOut[0].clientWidth }).css({ height: this.divOut[0].clientHeight });
            }
            if (FJ.isIEno9 && this.p.useImgBorder)
                this.pjBg.find(".pj_bg4").css({ height: this.divOut[0].clientHeight - 12 });
            this.pjBody.css({ width: "100%" }).css({ width: this.pjBody[0].clientWidth - this.p.borderWidthB * 2 }).css({ height: "100%" }).css({ height: this.pjBody[0].clientHeight - this.p.borderWidthB * 2 });
            if (this.p.cbM)
                this.p.cbM.call(this);
        },
        //#endregion

        //#region 显示/隐藏ie6下的遮挡Iframe
        showIfr: function (isShow, pos) {
            if (this.p.hasIfr) {
                if (isShow) {
                    if (pos == null) {
                        pos = {
                            width: this.p.widthF + 8,
                            height: this.p.heightF + (this.p.borderWidth >= 3 ? this.p.borderWidth + 27 : 28),
                            left: this.p.leftF,
                            top: this.p.topF
                        };
                    }
                    this.pjIframe.css(pos).show();
                }
                else {
                    this.pjIframe.hide();
                }
            }
        }
        //#endregion
    });

    //#region 绑定到jquery
    $.fn.extend({
        PanelJ: function (settings) {
            //返回浮动层对象
            return new FJ.PanelJ(this, settings);
        },
        PJ: function (settings) {
            return $(this).PanelJ(settings);
        }
    });
    //#endregion

    //#region 图片文件夹路径
    PJ.imgFolderSrc = FJ.imgPath + "Panel/";
    //#endregion

    //#region 加载css
    $("head").append('<link id="PanelJStyle" href="' + FJ.cssPath + 'flareJ.Panel.css" rel="stylesheet" type="text/css" />');
    //#endregion

    //#region 检测层是否存在
    PJ.checkDiv = function (divName, isIdHead) {
        var re = false;
        if (isIdHead == null) {
            if ($("#PJ_" + divName).length > 0) {
                re = true;
            }
        }
        else {
            //查找ID词头相符的元素
            if ($("div[id^=PJ_" + divName + "]").length > 0) {
                re = true;
            }
        }

        return re;
    }
    //#endregion

    //#region 删除层
    PJ.deleteDiv = function (divName, isIdHead) {
        if (isIdHead == null) {
            $("#PJ_" + divName).remove();
        }
        else {
            //查找ID词头相符的元素
            $("div[id^=PJ_" + divName + "]").remove();
            //删除IE6下遮挡select的iframe
            if (FJ.isIE6) {
                $("iframe[id^=pj_ifr_" + divName + "]").remove();
            }
        }
    }
    //#endregion

    //#region 切换是否显示悬停层(全部)
    PJ.changeHoverShow = function (arrObj) {
        //遍历传入的层对象数组
        for (var i = 0; i < arrObj.length; i++) {
            if (arrObj[i] != null) {
                if (arrObj[i].st.isHoverShow) {
                    arrObj[i].st.isHoverShow = false;
                }
                else {
                    arrObj[i].st.isHoverShow = true;
                }
            }
        }
    }
    //#endregion

    //#region 特殊操作
    $(function () {
        //#region 创建一个不断刷新的隐藏元素解决IE6下滚动条位置改变时层无法遮住select的bug
        if (FJ.isIE6) {
            $("body").prepend("<div id='fDIe6Fix' style='display:none;'></div>");
            setInterval(function () {
                $("#fDIe6Fix").html("1");
            }, 200);
        }
        //#endregion
    });
    //#endregion
})(jQuery);